#include <iostream>

class Base
{
public:
    Base(int a):a(a){}
    void show()
    {
        std::cout<<"a = "<<a<<std::endl;
    }
    ~Base()
    {
        std::cout<<"父类析构"<<std::endl;
    }
private:
    int a;
};

class Derived:public Base
{
public:
    //子类在进行构造前，要先对父类进行构造
    //在子类的构造函数初始化列表中对父类进行构造——调用父类的构造函数
    Derived(int a,int b):Base(a),b(b){}
    //析构顺序:先子类,再父类
    ~Derived()
    {
        std::cout<<"子类析构"<<std::endl;
    }

    void show()
    {
        //名词遮蔽:当父类成员和子类成员重名时，父类成员在子类会被遮蔽
        //解决名词遮蔽的方法:声明函数的作用域
        Base::show();
        std::cout<<"b = "<<b<<std::endl;
    }
private:
    int b;
};

int main()
{
    Derived d(1,2);
    d.show();
    return 0;
}